package com.结构型模式.组合模式.原理;

import java.util.ArrayList;

/**
 * @author chenhs
 * @date 2020/11/8
 */
public class Bole1 implements IComponent {

	
	private String name;
	public Bole1(String name){
		this.name =name;
	}
	private ArrayList<IComponent> son =new ArrayList<IComponent>() ;
	
	@Override
	public void add(IComponent o) {
		son.add(o);
	}
	
	@Override
	public void remove(Integer Index) {
		System.out.println(Index);
		son.remove(Index);
	}
	
	@Override
	public IComponent getSon(Integer index) {
		
		return son.get(index);
	}
	@Override
	public void operation() {
		System.out.println(this.name+"被访问。");
		for (int i = 0; i < son.size(); i++) {
			son.get(i).operation();
		}
	}
}
